# -*- coding:utf-8 -*-
# api/business_scenario.py

from sanic import Blueprint, request, response
from sanic.log import logger
from sanic_ext import openapi

from business.business_scenario import (
    get_business_scenario,
    get_business_scenario_detail_by_id,
    query_business_scenario_like_name,
    query_business_scenario_by_main_busi_id
)

bp_business_scenario_v1 = Blueprint('BusinessScenario', url_prefix='/business_scenario', version=1)


@bp_business_scenario_v1.get('/')
@openapi.definition(
    tag='业务场景',
    summary='获取业务场景列表',
    description='获取业务场景列表',
    parameter=[],
)
async def get_business_scenario_interface(request: request.Request):
    logger.info(f"GET {request.url}")
    data_result = await get_business_scenario(request)
    return response.json(dict(data_result), content_type='application/json')


@bp_business_scenario_v1.route('/<busi_scenario_id>', methods=['GET'])
@openapi.definition(
    tag='业务场景',
    summary='根据业务场景ID查询业务场景详情',
    description='根据业务场景ID查询业务场景详情',
    parameter=[
        {
            "name": "busi_scenario_id",
            "type": "int",
            "schema": 1,
            "location": "path",
            "decription": "业务场景ID",
            "required": True,
            "deprecated": None,
            "allowEmptyValue": False,
        }
    ],
)
async def get_business_scenario_detail_interface(request: request.Request, busi_scenario_id: int):
    logger.info(f"GET {request.url}")
    data_result = await get_business_scenario_detail_by_id(busi_scenario_id, request)
    return response.json(dict(data_result), content_type='application/json')


@bp_business_scenario_v1.route('/filter', methods=['GET'])
@openapi.definition(
    tag='业务场景',
    summary='根据业务场景名称模糊查询业务场景列表',
    description='根据业务场景名称模糊查询业务场景列表',
    parameter=[
        {
            "name": "busi_scenario_name",
            "type": "string",
            "schema": "体彩缴款",
            "location": "query",
            "decription": "业务场景名称",
            "required": True,
            "deprecated": None,
            "allowEmptyValue": False,
        }
    ],
)
async def query_business_scenario_like_name_interface(request: request.Request):
    logger.info(f"GET {request.url}")
    busi_scenario_name = request.args.get('busi_scenario_name')
    data_result = await query_business_scenario_like_name(busi_scenario_name, request)
    return response.json(dict(data_result), content_type='application/json')


@bp_business_scenario_v1.route('/main_busi_id/<main_busi_id>', methods=['GET'])
@openapi.definition(
    tag='业务场景',
    summary='根据主体业务ID查询业务场景列表',
    description='根据主体业务ID查询业务场景列表',
    parameter=[
        {
            "name": "main_busi_id",
            "type": "int",
            "schema": 1,
            "location": "path",
            "decription": "主体业务ID",
            "required": True,
            "deprecated": None,
            "allowEmptyValue": False,
        }
    ],
)
async def query_business_scenario_by_main_busi_id_interface(request: request.Request, main_busi_id: int):
    logger.info(f"GET {request.url}")
    data_result = await query_business_scenario_by_main_busi_id(main_busi_id, request)
    return response.json(dict(data_result), content_type='application/json')
